import { Component,Input } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { TopicInfo, RowInfo, DropdownInfo } from '../../models/quesinfo';


/**
 * Generated class for the QueationLinkagePage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */


@Component({
  selector: 'page-queation-linkage',
  templateUrl: 'queation-linkage.html',
})
export class QueationLinkagePage {
  @Input() topic: TopicInfo;@Input() poneSet: Array<any>;
  @Input() topicIndex;
  topicIndexshow;
  selectCount:number;
  constructor(public navCtrl: NavController, public navParams: NavParams) {
    
  }
  ngOnInit(): void {
    this.topicIndexshow=this.topicIndex+1;
    this.selectCount=this.topic.listColumn.length;
  }
  ionViewDidLoad() {
    //console.log('ionViewDidLoad QueationLinkagePage');
  }
  changeselect10017(itemC){
    if(itemC.FTempResult=="-1")
    {
        if(itemC.FSort<this.selectCount){
          //
           let nextitemC= this.topic.listColumn.find(onec=>onec.FSort==(itemC.FSort+1));
           if(nextitemC!=null&&nextitemC!=undefined){
            nextitemC.Dropdowns=[];
            let temonedq=new DropdownInfo();
             temonedq.FDOptionId="-1";
             temonedq.FOptionContent=""+nextitemC.FCOptionContent;
             temonedq.FCSort=0;
             temonedq.FCid=nextitemC.FCOptionId;
             temonedq.FPid="-1";
             nextitemC.Dropdowns.push(temonedq);
             nextitemC.FTempResult="-1";
             //
             //
             if(itemC.FSort<(this.selectCount-1))
             {
                 let otherlistc=this.topic.listColumn.filter(p=>p.FSort>nextitemC.FSort);
                 if(otherlistc!=null&&otherlistc!=undefined&&otherlistc.length!=0){
                   otherlistc.forEach(onecc => {
                     onecc.Dropdowns=[];
                     let temonedq=new DropdownInfo();
                temonedq.FDOptionId="-1";
                temonedq.FOptionContent=""+onecc.FCOptionContent;
                temonedq.FCSort=0;
                temonedq.FCid=onecc.FCOptionId;
                temonedq.FPid="-1";
                onecc.Dropdowns.push(temonedq);
                  onecc.FTempResult="-1";
                     });
                 }
             }
          }
        }
    }
    else {
      if(itemC.FSort<this.selectCount){
        //
         let nextitemC= this.topic.listColumn.find(onec=>onec.FSort==(itemC.FSort+1));
         if(nextitemC!=null&&nextitemC!=undefined){
          nextitemC.Dropdowns=[];
          //console.log(nextitemC.Dropdowns);
          let temonedq=new DropdownInfo();
           temonedq.FDOptionId="-1";
           temonedq.FOptionContent=""+nextitemC.FCOptionContent;
           temonedq.FCSort=0;
           temonedq.FCid=nextitemC.FCOptionId;
           temonedq.FPid="-1";
           nextitemC.Dropdowns.push(temonedq);
          //  if(onec.FSort==1){
            this.topic.Dropdowns.forEach(oned => {
              if(oned.FCid==nextitemC.FCOptionId&&oned.FPid==itemC.FTempResult){
                nextitemC.Dropdowns.push(oned);
              }
            });
            //console.log(nextitemC.Dropdowns);
          //  };
           nextitemC.FTempResult="-1";
           //
        }
        //
        if(itemC.FSort<(this.selectCount-1))
        {
            let otherlistc=this.topic.listColumn.filter(p=>p.FSort>nextitemC.FSort);
            if(otherlistc!=null&&otherlistc!=undefined&&otherlistc.length!=0){
              otherlistc.forEach(onecc => {
                onecc.Dropdowns=[];
                let temonedq=new DropdownInfo();
           temonedq.FDOptionId="-1";
           temonedq.FOptionContent=""+onecc.FCOptionContent;
           temonedq.FCSort=0;
           temonedq.FCid=onecc.FCOptionId;
           temonedq.FPid="-1";
           onecc.Dropdowns.push(temonedq);
             onecc.FTempResult="-1";
                });
            }
        }
      }
    }
  }
}
